package com.zzy;

import java.io.IOException;
import java.net.MalformedURLException;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class HtmlUnitDemo {

	private static String TARGET_URL = "http://localhost:8081/pd4ml-demo/a.html";

	public static void main(String[] args)
			throws FailingHttpStatusCodeException, MalformedURLException,
			IOException {
		       // 模拟一个浏览器
				WebClient webClient = new WebClient();
				webClient.setAjaxController(new NicelyResynchronizingAjaxController());
				webClient.setJavaScriptEnabled(true);
				// 模拟浏览器打开一个目标网址
				HtmlPage rootPage = webClient.getPage(TARGET_URL);

		//body html信息
		//HtmlElement htmlElement = rootPage.getBody();
		//String xmlContent = htmlElement.asXml();
		String textStr=rootPage.asXml();
		System.out.println(textStr);
		
		//酱获取到的  html转成文件
		//FileOperation.contentToTxt("E:\\java\\html\\123.html",textStr);
	}
}